package org.git.movie.service.impl;

import org.git.movie.entity.FfList;
import org.git.movie.mapper.FfNavMapper;
import org.git.movie.service.FfListService;
import org.git.movie.service.FfNavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import org.git.movie.vo.*;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 */
@Service
public class FfNavServiceImpl  implements FfNavService {


    @Resource
    private FfNavMapper ffNavMapper;

    @Resource
    private FfListService ffListService;


    @Override
    public List<FfNavVO> findAvailNavList() {

        int pid = 0 ;
        List<FfNavVO> list =   ffNavMapper.findAvailAblearentByPid(pid);
        if(list != null && list.size() >= 1){
            List<FfNavVO> childlist = null;

            for(FfNavVO item: list){
                renderType(  item);
                childlist =   ffNavMapper.findAvailAblearentByPid(item.getNavId());
                if(childlist != null && childlist.size() >= 1){
                    for(FfNavVO item2: childlist){
                        renderType(  item2);
                    }
                }
                item.setChilds(childlist);

            }
        }

        return list;
    }

    private void renderType(FfNavVO item){
        if(item == null){
            return;
        }
        List<FfNavVO> childlist = null;
        List<ListExtendVo> listExtendVos = null;
        FfList ffList = null;
        String listExtend = null;
        if(item.getNavListId() != null){
            ffList = ffListService.findById(item.getNavListId());
            if(ffList != null){
                listExtend =  ffList.getListExtend();

                listExtendVos =ffListService.pareseEntend2ListExtendVo(listExtend);

                item.setExtendList(listExtendVos);
            }
        }
    }
}
